package colorChanger;

public class CMYK {
	private CMYKColor c;
	private CMYKColor m;
	private CMYKColor y;
	private CMYKColor k;

	public CMYK(){
	}
	public CMYK(double c, double m, double y, double k) {
		setC(new CMYKColor(c, CMYKColor.CYAN));
		setM(new CMYKColor(m, CMYKColor.MAGENTA));
		setY(new CMYKColor(y, CMYKColor.YELLOW));
		setK(new CMYKColor(k, CMYKColor.KEY));

		turnCMYKPure();
	}

	private void turnCMYKPure() {
		if (isCMYKKey()) {
			turnCMYKKey();
		} else if (getC().getAbsoluteIntensity() > CMYKColor.STRONG) {
			turnCMYKCyan();
		} else if (getM().getAbsoluteIntensity() > CMYKColor.STRONG) {
			turnCMYKMagenta();
		} else if (getY().getAbsoluteIntensity() > CMYKColor.STRONG) {
			turnCMYKYellow();
		}
	}

	private void turnCMYKYellow() {
		setC(new CMYKColor(0, CMYKColor.CYAN));
		setM(new CMYKColor(0, CMYKColor.MAGENTA));
		setY(new CMYKColor(1, CMYKColor.YELLOW));
		setK(new CMYKColor(0, CMYKColor.KEY));
	}

	private void turnCMYKMagenta() {
		setC(new CMYKColor(0, CMYKColor.CYAN));
		setM(new CMYKColor(1, CMYKColor.MAGENTA));
		setY(new CMYKColor(0, CMYKColor.YELLOW));
		setK(new CMYKColor(0, CMYKColor.KEY));
	}

	private void turnCMYKCyan() {
		setC(new CMYKColor(1, CMYKColor.CYAN));
		setM(new CMYKColor(0, CMYKColor.MAGENTA));
		setY(new CMYKColor(0, CMYKColor.YELLOW));
		setK(new CMYKColor(0, CMYKColor.KEY));
	}

	private void turnCMYKKey() {
		setC(new CMYKColor(0, CMYKColor.CYAN));
		setM(new CMYKColor(0, CMYKColor.MAGENTA));
		setY(new CMYKColor(0, CMYKColor.YELLOW));
		setK(new CMYKColor(1, CMYKColor.KEY));
	}

	private boolean isCMYKKey() {
		return getC().getAbsoluteIntensity() + getM().getAbsoluteIntensity()
				+ getY().getAbsoluteIntensity() + getK().getAbsoluteIntensity()
				/ 4 > CMYKColor.VERY_STRONG;
	}

	public CMYKColor getC() {
		return c;
	}

	public void setC(CMYKColor c) {
		this.c = c;
	}

	public CMYKColor getM() {
		return m;
	}

	public void setM(CMYKColor m) {
		this.m = m;
	}

	public CMYKColor getY() {
		return y;
	}

	public void setY(CMYKColor y) {
		this.y = y;
	}

	public CMYKColor getK() {
		return k;
	}

	public void setK(CMYKColor k) {
		this.k = k;
	}

	//
	//
	//
	public String toString() {
		return "" + c.getIniticalColorIntensity() + " "
				+ m.getIniticalColorIntensity() + " "
				+ y.getIniticalColorIntensity() + " "
				+ k.getIniticalColorIntensity() + " ";
	}

}
